﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Derrick.Web
{
    public partial class TwitterTestPage : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            string twitterRestAPI = ConfigurationManager.AppSettings["TwitterRestAPI"];
            string twitterUsername = ConfigurationManager.AppSettings["TwitterUsername"];
            string twitterPassword = ConfigurationManager.AppSettings["TwitterPassword"];

            WebRequest twitterRequest = WebRequest.Create(twitterRestAPI);
            twitterRequest.Method = "GET";
            twitterRequest.ContentType = "application/json";
            twitterRequest.Credentials = new NetworkCredential(twitterUsername, twitterPassword);
            Encoding encode = Encoding.GetEncoding("utf-8");



            WebResponse twitterResponse = twitterRequest.GetResponse();


            StreamReader twitterStream = new StreamReader(twitterResponse.GetResponseStream(), encode);

            while (!twitterStream.EndOfStream)
            {
                string twitterMessage = twitterStream.ReadLine();
                //do something with twitterMessage...
            }

        }
    }
}